package com.example.demo.Controller.admin;

import com.example.demo.Mapper.AdminMapper;
import com.example.demo.Service.AdminServiceImpl;
import com.example.demo.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private AdminServiceImpl mapper;
    @PostMapping("/admin/LoginCheck")
    public String LoginCheck(Admin admin, HttpSession session, RedirectAttributes redirectAttributes){
        if (mapper.CheckAdmin(admin)){
            session.setAttribute("user",admin);
            return "redirect:admin/inputs";
        }
        return "redirect:admin/Login";
    }

    @RequestMapping("/admin/logout")
    public String logout(HttpSession session){
        session.removeAttribute("user");
        return "redirect:/";
    }
}
